/*
 Copyright (c) 2013 MeherTJ G. All rights reserved.
 License: LGPL for personnal study or free software.
 */

#pragma once

#include <exception>
#include <string>

namespace Zen
{
	template <typename Integer>
	class Error
	{
	public:
		Error(Integer eno) noexcept
		{
			mErrorNum = eno;
			mActived = (eno != 0);
		}

		Error(Error&& ec) noexcept
		{
			mErrorNum = ec.mErrorNum;
			mActived = ec.mActived;
			ec.mActived = false;
		}

		~Error() noexcept
		{
			(mActived && mErrorNum) ? (abort(), 0) : 0;
		}

		void Ignore() const
		{
			mActived = false;
		}

		auto GetCode() const -> int
		{
			mActived = false;
			return mErrorNum;
		}

		auto IsOK() const -> bool
		{
			mActived = false;
			return mErrorNum == 0;
		}

		Error& operator=(Error&& ec)
		{
			mErrorNum = ec.mErrorNum;
			mActived = ec.mActived;
			ec.mActived = false;
			return *this;
		}

	private:
		Integer mErrorNum{};
		mutable bool mActived = false;
	};
} // namespace Zen
